<?php
/**
 * Pert PHP Library
 * SQLGenerator
 * Input Class
 *
 * @author	Emre Hasegeli <hasegeli@gmail.com>
 * @license	GNU General Public License v3
 */

namespace Pert\PostgreSQLGenerator;

class Input
{
	private $id;

	public function __Construct($id)
	{
		$this->id = $id;
	}

	public function SQL()
	{
		if(is_array($this->id))
		{
			require_once __DIR__ . '/ArrayInput.php';

			return new ArrayInput($this->id);
		}

		if(is_bool($this->id))
			if($this->id)
				return 'true';
			else
				return 'false';

		if($this->id instanceof \DateTime)
			return "'" . $this->id->format('Y-m-d') . "'";

		if(is_int($this->id))
			return $this->id;

		if(is_float($this->id))
			return $this->id;

		if(!$this->id)
			return 'NULL';

		$id = $this->id;

		if(get_magic_quotes_gpc())
			$id = stripslashes($id);

		$id = pg_escape_string($id);

		return "'" . $id . "'";
	}

	public function StringSQL()
	{
		$id = trim($this->id);

		if(get_magic_quotes_gpc())
			$id = stripslashes($id);

		$id = pg_escape_string($id);

		return "'" . $id . "'";
	}

	public function LikeStringSQL()
	{
		$id = trim($this->id);

		if(get_magic_quotes_gpc())
			$id = stripslashes($id);

		$id = pg_escape_string($id);

		return "'%" . $id . "%'";
	}
}
